module Maze
  module TextFormatter
    class Sigma
      include DrawingHelpers

      attr_reader :maze, :canvas

      def initialize(maze)
        @maze = maze
        @canvas = Array.new(maze.height * 2 + 2) do
          Array.new(maze.width * 2 + 2, ' ')
        end

        canvas_draw
      end

      private

      def calculate_origin(for_point)
        for_point.update do |other|
          other.x *= 2
          other.y *= 2
        end
      end

      def calculate_offset(*args)
        direction, point = args

        shift_y = maze.shifted_down?(point) ? 1 : 0

        case direction
        when :north      then Point.new(1, 0 + shift_y)
        when :north_west then Point.new(0, 1 + shift_y)
        when :north_east then Point.new(2, 1 + shift_y)
        when :south_west then Point.new(0, 2 + shift_y)
        when :south      then Point.new(1, 2 + shift_y)
        when :south_east then Point.new(2, 2 + shift_y)
        end
      end

      def select_character(direction)
        case direction
        when :north, :south           then "_"
        when :north_west, :south_east then "/"
        when :north_east, :south_west then "\\"
        end
      end
    end
  end
end

